var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        return new (o || (o = Promise))(function (i, a) {
            function r(e) {
                try {
                    c(n.next(e));
                } catch (t) {
                    a(t);
                }
            }
            function s(e) {
                try {
                    c(n.throw(e));
                } catch (t) {
                    a(t);
                }
            }
            function c(e) {
                var t;
                e.done
                    ? i(e.value)
                    : ((t = e.value),
                      t instanceof o
                          ? t
                          : new o(function (e) {
                                e(t);
                            })).then(r, s);
            }
            c((n = n.apply(e, t || [])).next());
        });
    },
    s = function (e, t) {
        var o,
            n,
            i,
            a,
            r = {
                label: 0,
                sent: function () {
                    if (1 & i[0]) throw i[1];
                    return i[1];
                },
                trys: [],
                ops: []
            };
        return (
            (a = {next: s(0), throw: s(1), return: s(2)}),
            "function" == typeof Symbol &&
                (a[Symbol.iterator] = function () {
                    return this;
                }),
            a
        );
        function s(e) {
            return function (t) {
                return c([e, t]);
            };
        }
        function c(a) {
            if (o) throw new TypeError("Generator is already executing.");
            for (; r; )
                try {
                    if (
                        ((o = 1),
                        n &&
                            (i = 2 & a[0] ? n.return : a[0] ? n.throw || ((i = n.return) && i.call(n), 0) : n.next) &&
                            !(i = i.call(n, a[1])).done)
                    )
                        return i;
                    switch (((n = 0), i && (a = [2 & a[0], i.value]), a[0])) {
                        case 0:
                        case 1:
                            i = a;
                            break;
                        case 4:
                            return r.label++, {value: a[1], done: !1};
                        case 5:
                            r.label++, (n = a[1]), (a = [0]);
                            continue;
                        case 7:
                            (a = r.ops.pop()), r.trys.pop();
                            continue;
                        default:
                            if (!(i = (i = r.trys).length > 0 && i[i.length - 1]) && (6 === a[0] || 2 === a[0])) {
                                r = 0;
                                continue;
                            }
                            if (3 === a[0] && (!i || (a[1] > i[0] && a[1] < i[3]))) {
                                r.label = a[1];
                                break;
                            }
                            if (6 === a[0] && r.label < i[1]) {
                                (r.label = i[1]), (i = a);
                                break;
                            }
                            if (i && r.label < i[2]) {
                                (r.label = i[2]), r.ops.push(a);
                                break;
                            }
                            i[2] && r.ops.pop(), r.trys.pop();
                            continue;
                    }
                    a = t.call(e, r);
                } catch (s) {
                    (a = [6, s]), (n = 0);
                } finally {
                    o = i = 0;
                }
            if (5 & a[0]) throw a[1];
            return {value: a[0] ? a[1] : void 0, done: !0};
        }
    };
Object.defineProperty(i, "__esModule", {value: !0});
var c = e("AssetsMap"),
    l = e("BundleNames"),
    d = e("GlobalParam"),
    u = e("LocalItemName"),
    p = e("Util"),
    h = e("AccountRequest"),
    f = e("LoginVO"),
    _ = (function (e) {
        function t() {
            var o = e.call(this, t.NAME, new f.default()) || this;
            return (o.timestamp = {num: 0, time: 0}), o;
        }
        return (
            a(t, e),
            (t.prototype.platformLogin = function () {
                return r(this, void 0, void 0, function () {
                    return s(this, function () {
                        switch (ad.curr_platform) {
                            case window.ad.Platform.WECHAT:
                            case window.ad.Platform.TOU_TIAO:
                            default:
                                (this.loginVO.openID = this.getLocalOpenID()), this.onLoginSuccess();
                        }
                        return [2];
                    });
                });
            }),
            (t.prototype.onLoginSuccess = function () {
                this.sendNotification(t.ON_GET_OPENID_SUCCESS);
            }),
            Object.defineProperty(t.prototype, "loginVO", {
                get: function () {
                    return this.data;
                },
                enumerable: !1,
                configurable: !0
            }),
            (t.prototype.login = function (e) {
                return r(this, void 0, void 0, function () {
                    var t,
                        o,
                        n,
                        i = this;
                    return s(this, function () {
                        return (t = JSON.parse(p.default.getItem(u.default.LOCAL_LOGIN_CACHE, "{}"))).token &&
                            t.timestamp &&
                            t.openId &&
                            ((o = new Date().getTime() / 1e3), (n = t.timestamp), o - n < 72e3)
                            ? ((this.loginVO.token = t.token),
                              (this.loginVO.openID = t.openId),
                              (this.loginVO.timestamp = t.timestamp),
                              game.log("读取缓存token", t),
                              this.onLoginSuccess(),
                              [2])
                            : (console.log("是这里登陆失败吗？"),
                              h.default
                                  .requestLogin(d.default.game_uid, e.code)
                                  .then(function (e) {
                                      game.log("请求登录回调", e),
                                          p.default.setItem(u.default.LOCAL_LOGIN_CACHE, JSON.stringify(e));
                                      var t = e.openId,
                                          o = e.token,
                                          n = e.timestamp;
                                      (i.loginVO.token = o),
                                          (i.loginVO.openID = t),
                                          (i.loginVO.timestamp = n),
                                          i.onLoginSuccess();
                                  })
                                  .catch(function (e) {
                                      game.error("登录失败,error:", e), i.onLoginFail();
                                  }),
                              [2]);
                    });
                });
            }),
            (t.prototype.qqLogin = function (e, t) {
                window.qq.login({
                    success: function (o) {
                        o.code ? e && e(o) : t();
                    },
                    fail: function () {
                        t();
                    }
                });
            }),
            (t.prototype.onLoginFail = function () {
                game.UIManager.instance.showToast("登录服务器失败"),
                    game.UIManager.instance.replaceModuleView(
                        l.default.Start,
                        c.default.StartBundle.prefabs.assetsList.StartModuleView
                    );
            }),
            (t.prototype.getLocalOpenID = function () {
                var e = p.default.getItem(u.default.RANDOM_OPEN_ID, "" + p.default.randomFrom(1e5, 999999));
                return p.default.setItem(u.default.RANDOM_OPEN_ID, e), e;
            }),
            (t.prototype.isOpenEatChicken = function () {
                return !0;
            }),
            (t.prototype.getEggInfo = function () {
                var e = p.default.getItem("eggInfo", "-");
                return "-" === e
                    ? ((this.timestamp.time = new Date().getTime()), this.timestamp)
                    : ((this.timestamp = JSON.parse(e)),
                      this.timestamp.time < p.default.startDayTimestamp() &&
                          ((this.timestamp.time = new Date().getTime()), (this.timestamp.num = 0)),
                      this.timestamp);
            }),
            (t.prototype.setEggInfo = function () {
                (this.timestamp.time = new Date().getTime()),
                    (this.timestamp.num += 1),
                    p.default.setItem("eggInfo", JSON.stringify(this.timestamp));
            }),
            (t.NAME = "LoginProxy"),
            (t.ON_LOGIN_SUCCESS = "ON_LOGIN_SUCCESS"),
            (t.ON_COIN_CHANGE = "ON_COIN_CHANGE"),
            (t.ON_GET_OPENID_SUCCESS = "ON_GET_OPENID_SUCCESS"),
            t
        );
    })(puremvc.Proxy);
i.default = _;
